package com.authine.cloudpivot.web.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.service.ShopInspectionService;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "店检需求", tags = "店检需求相关接口")
@RestController
@RequestMapping("/api/shopInspection")
@Slf4j
public class ShopInspectionController extends BaseController {

    @Autowired
    private ShopInspectionService shopInspectionService;

    /**
     * 店检需求创建门店 店检需求id
     * @param
     * @return
     */
    @ApiOperation(value = "店检需求创建门店" )
    @GetMapping("/createStore")
    @ResponseBody
    public ResponseResult<?> createPosition(@RequestParam("id") String id,@RequestParam("code") String code){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            shopInspectionService.createStore(id,code);
            json.put("message","门店新增成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "门店新增失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }

    @ApiOperation(value = "更新店检需求")
    @GetMapping("/updateShopInspection")
    public ResponseResult<?> updateShopInspection(@RequestParam("id") String id,@RequestParam("updateId") String updateId) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            shopInspectionService.updateShopInspection(id,updateId);
            json.put("message","更新店检需求成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "更新店检需求失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }
}
